package com.usdt.system.service.impl.cp;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.usdt.common.core.domain.entity.SysDictData;
import com.usdt.common.core.redis.RedisClient;
import com.usdt.common.utils.bean.BeanUtil;
import com.usdt.system.cp.utils.UserAndDeptUtils;
import com.usdt.system.domain.req.ConditionReqVO;
import com.usdt.system.domain.resp.RoomBuildingNumber2RespVo;
import com.usdt.system.domain.resp.RoomBuildingNumberRespVO;
import com.usdt.system.domain.resp.RoomSaleChart2RespVo;
import com.usdt.system.domain.resp.RoomSaleChartCustomerRespVo;
import com.usdt.system.domain.resp.RoomSalesChartRespVo;
import com.usdt.system.dto.cp.RoomSaleChartExcelDTO;
import com.usdt.system.dto.cp.SignUserExcelDTO;
import com.usdt.system.service.ISysDictTypeService;
import com.usdt.system.service.cp.RequestManageService;
import com.usdt.system.service.cp.SalesChartService;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class SalesChartServiceImpl implements SalesChartService{
	
	private final String BUILDING_NUMBER = "/api-v1/roomInfo/buildingNumber";// 获取楼层楼栋api
	
	private final String ROOM_INFO = "/api-v1/roomInfo/roomInfo";// 获取房间信息
	
	private final String ROOM_INFO_PAGE = "/api-v1/roomInfo/roomInfo/page";// 获取房间信息分页
	
	@Autowired
	private RequestManageService requestManageService;
	
	@Autowired
	private ISysDictTypeService dictTypeService;
	
	@Autowired
	private RedisClient redisClient;
	
	@Override
	public List<RoomBuildingNumberRespVO> buildingNumber(List<String> deptIds) {
		List<RoomBuildingNumberRespVO> result = new ArrayList<RoomBuildingNumberRespVO>();
		if (CollectionUtils.isEmpty(deptIds)) {
			deptIds = Arrays.asList(UserAndDeptUtils.getCurrentDeptId());
		}
		String url = BUILDING_NUMBER+"?currentUserId="+UserAndDeptUtils.getCurrentUserId()+"&currentDeptId="+UserAndDeptUtils.getCurrentDeptId();
		String reKey = BUILDING_NUMBER;
		if(!CollectionUtils.isEmpty(deptIds)) {
			url = url+"&deptIds="+String.join(",", deptIds);
			reKey = reKey+"&deptIds="+String.join(",", deptIds);
		}
		//String resp = requestManageService.getMethod(url, String.class);
		String resp = getResp(url,reKey);
		if(StringUtils.isBlank(resp)) {
			return result;
		}
		List<RoomBuildingNumber2RespVo> roomBuildingNumberList = JSON.parseObject(resp).getList("data",RoomBuildingNumber2RespVo.class);
		if(CollectionUtils.isEmpty(roomBuildingNumberList)) {
			return result;
		}
		
		Map<String, List<RoomBuildingNumber2RespVo>> map = roomBuildingNumberList.stream().collect(Collectors.groupingBy(RoomBuildingNumber2RespVo::getBuilding));
		List<String> keyList = map.keySet().stream().collect(Collectors.toList());
		keyList.sort((String s1,String s2)->Integer.valueOf(s1).compareTo(Integer.valueOf(s2)));
		for (String key : keyList) {
			RoomBuildingNumberRespVO vo = new RoomBuildingNumberRespVO();
			vo.setBuilding(key);
			List<RoomBuildingNumber2RespVo> list = map.get(key);
			List<String> floorList = list.stream().map(RoomBuildingNumber2RespVo::getFloor)
				.sorted((String s1,String s2)->Integer.valueOf(s1).compareTo(Integer.valueOf(s2)))
				.toList();
			vo.setFloorList(floorList);
			result.add(vo);
		}
		return result;
	}


	@Override
	public RoomSalesChartRespVo getRoomInfo(List<String> buildings, List<String> floors, String roomName, List<String> numbers,
			List<String> vipTypes, List<String> faces, String status, String roomType
			,Integer pageNum,Integer pageSize) {
		RoomSalesChartRespVo result = new RoomSalesChartRespVo();
		IPage page = new Page();
		page.setCurrent(pageNum);
		page.setSize(pageSize);
		page.setTotal(0);
		result.setPageList(page);
		List<String> deptIds = Arrays.asList(UserAndDeptUtils.getCurrentDeptId());
		String url = ROOM_INFO_PAGE+"?currentUserId="+UserAndDeptUtils.getCurrentUserId()+"&currentDeptId="+UserAndDeptUtils.getCurrentDeptId();
		if(!CollectionUtils.isEmpty(deptIds)) {
			url = url+"&deptIds="+String.join(",", deptIds);
		}
		if(!CollectionUtils.isEmpty(buildings)) {
			url = url+"&buildings="+String.join(",", buildings);
		}
		if(!CollectionUtils.isEmpty(floors)) {
			url = url+"&floors="+String.join(",", floors);
		}
		if(StringUtils.isNotBlank(roomName)) {
			url = url+"&roomName="+roomName;
		}
		if(!CollectionUtils.isEmpty(numbers)) {
			url = url+"&numbers="+String.join(",", numbers);
		}
		if(!CollectionUtils.isEmpty(vipTypes)) {
			url = url+"&vipTypes="+String.join(",", vipTypes);
		}
		if(!CollectionUtils.isEmpty(faces)) {
			url = url+"&faces="+String.join(",", faces);
		}
		if(StringUtils.isNotBlank(status)) {
			url = url+"&status="+status;
		}
		if(StringUtils.isNotBlank(roomType) && !"全部".equals(roomType)) {
			url = url+"&roomType="+roomType;
		}
		if(null!=pageNum) {
			url = url+"&pageNum="+pageNum;
		}
		if(null!=pageSize) {
			url = url+"&pageSize="+pageSize;
		}
		String resp = requestManageService.getMethod(url, String.class);
		if(StringUtils.isBlank(resp)) {
			return result;
		}
		List<RoomSaleChart2RespVo> roomBuildingNumberList = JSON.parseObject(resp).getList("data",RoomSaleChart2RespVo.class);
		if(CollectionUtils.isEmpty(roomBuildingNumberList)) {
			return result;
		}
		/*roomBuildingNumberList.sort((RoomSaleChart2RespVo r1,RoomSaleChart2RespVo r2)->{
			int compareTo = Integer.valueOf(r1.getBuilding()).compareTo(Integer.valueOf(r2.getBuilding()));
			if(0==compareTo) {
				int compareTo2 = Integer.valueOf(r1.getFloor()).compareTo(Integer.valueOf(r2.getFloor()));
				if(0==compareTo2) {
					return r1.getRoomName().compareTo(r2.getRoomName());
				}
				return compareTo2;
			}
			return compareTo;
		});*/
		
		for (RoomSaleChart2RespVo roomSaleChart2RespVo : roomBuildingNumberList) {
			String sRoomType = roomSaleChart2RespVo.getRoomType();
			if("护理".equals(sRoomType)) {
				String room = roomSaleChart2RespVo.getRoom();
				if(StringUtils.isBlank(room)) {
					roomSaleChart2RespVo.setRoom(this.getRoom(roomSaleChart2RespVo.getRoomName(),roomSaleChart2RespVo.getRoom()));
				}
			}
		}
		//分页
		page.setRecords(roomBuildingNumberList);
		page.setCurrent(pageNum);
		page.setSize(pageSize);
		//page.setTotal(roomBuildingNumberList.size());
		result.setPageList(page);
		return result;
	}
	
	@Override
	public RoomSalesChartRespVo getRoomInfoCount(List<String> buildings, List<String> floors, String roomName, List<String> numbers,
			List<String> vipTypes, List<String> faces, String status, String roomType) {
		RoomSalesChartRespVo result = new RoomSalesChartRespVo();
		/*IPage page = new Page();
		page.setCurrent(pageNum);
		page.setSize(pageSize);
		page.setTotal(0);
		result.setPageList(page);*/
		List<String> deptIds = Arrays.asList(UserAndDeptUtils.getCurrentDeptId());
		String url = ROOM_INFO+"?currentUserId="+UserAndDeptUtils.getCurrentUserId()+"&currentDeptId="+UserAndDeptUtils.getCurrentDeptId();
		String key = ROOM_INFO;
		if(!CollectionUtils.isEmpty(deptIds)) {
			url = url+"&deptIds="+String.join(",", deptIds);
			key = key+"&deptIds="+String.join(",", deptIds);
		}
		if(!CollectionUtils.isEmpty(buildings)) {
			url = url+"&buildings="+String.join(",", buildings);
			key = key+"&buildings="+String.join(",", buildings);
		}
		if(!CollectionUtils.isEmpty(floors)) {
			url = url+"&floors="+String.join(",", floors);
			key = key+"&floors="+String.join(",", floors);
		}
		if(StringUtils.isNotBlank(roomName)) {
			url = url+"&roomName="+roomName;
			key = key+"&roomName="+roomName;
		}
		if(!CollectionUtils.isEmpty(numbers)) {
			url = url+"&numbers="+String.join(",", numbers);
			key = key+"&numbers="+String.join(",", numbers);
		}
		if(!CollectionUtils.isEmpty(vipTypes)) {
			url = url+"&vipTypes="+String.join(",", vipTypes);
			key = key+"&vipTypes="+String.join(",", vipTypes);
		}
		if(!CollectionUtils.isEmpty(faces)) {
			url = url+"&faces="+String.join(",", faces);
			key = key+"&faces="+String.join(",", faces);
		}
		if(StringUtils.isNotBlank(status)) {
			url = url+"&status="+status;
			key = key+"&status="+status;
		}
		if(StringUtils.isNotBlank(roomType) && !"全部".equals(roomType)) {
			url = url+"&roomType="+roomType;
			key = key+"&roomType="+roomType;
		}
		//String resp = requestManageService.getMethod(url, String.class);
		String resp = getResp(url,key);
		if(StringUtils.isBlank(resp)) {
			return result;
		}
		List<RoomSaleChart2RespVo> roomBuildingNumberList = JSON.parseObject(resp).getList("data",RoomSaleChart2RespVo.class);
		if(CollectionUtils.isEmpty(roomBuildingNumberList)) {
			return result;
		}
		
		//总房间数
		Integer roomNumTotal = 0;
		//入住房间数
		Integer chechInRoomNumTotal = 0;
		//不可租房间数
		Integer notRentRoomNumTotal = 0;
		
		//总床位数
		Integer bedNumTotal = 0;
		//入住床位数
		Integer chechInBedNumTotal = 0;
		//不可租床位数
		Integer notRentBedNumTotal = 0;
		
		//入住人数
		Integer peopleNumTotal = 0;
		//占用床位数
		Integer occupyBedNumTotal = 0;
		
		//人数
		Set<String> customerIdSet = new HashSet<>();
		//护理
		List<RoomSaleChart2RespVo> huliList = new ArrayList<RoomSaleChart2RespVo>();
		
		for (RoomSaleChart2RespVo roomSaleChart2RespVo : roomBuildingNumberList) {
			String roomType2 = roomSaleChart2RespVo.getRoomType();
			String roomStatus = StringUtils.isBlank(roomSaleChart2RespVo.getStatus())?"":roomSaleChart2RespVo.getStatus();
			String number = StringUtils.isBlank(roomSaleChart2RespVo.getNumber())?"":roomSaleChart2RespVo.getNumber();
			if("自理".equals(roomType2) || "短住".equals(roomType2)) {
				if("入住中".equals(roomStatus)) {
					chechInRoomNumTotal=chechInRoomNumTotal+1;
					if("单人间".equals(number)) {
						chechInBedNumTotal = chechInBedNumTotal+1;
					}else {
						chechInBedNumTotal = chechInBedNumTotal+2;
					}
				}
				if("不可租".equals(roomStatus)) {
					notRentRoomNumTotal=notRentRoomNumTotal+1;
					if("单人间".equals(number)) {
						notRentBedNumTotal = notRentBedNumTotal+1;
					}else {
						notRentBedNumTotal = notRentBedNumTotal+2;
					}
				}
				if("单人间".equals(number)) {
					bedNumTotal = bedNumTotal+1;
				}else {
					bedNumTotal = bedNumTotal+2;
				}
				roomNumTotal = roomNumTotal+1;
			}
			
			if("护理".equals(roomType2)) {
				String room = roomSaleChart2RespVo.getRoom();
				String checkInSituation = StringUtils.isBlank(roomSaleChart2RespVo.getCheckInSituation())?"":roomSaleChart2RespVo.getCheckInSituation();
				if(StringUtils.isBlank(room)) {
					roomSaleChart2RespVo.setRoom(this.getRoom(roomSaleChart2RespVo.getRoomName(),roomSaleChart2RespVo.getRoom()));
				}
				if("入住中".equals(roomStatus)) {
					chechInBedNumTotal=chechInBedNumTotal+1;
				}
				if("不可租".equals(roomStatus)) {
					notRentBedNumTotal=notRentBedNumTotal+1;
				}
				if(checkInSituation.contains("占用")) {
					occupyBedNumTotal = occupyBedNumTotal+1;
				}
				bedNumTotal = bedNumTotal+1;
				huliList.add(roomSaleChart2RespVo);
			}
			
			//人员
			List<RoomSaleChartCustomerRespVo> customerList = roomSaleChart2RespVo.getCustomerList();
			if(!CollectionUtils.isEmpty(customerList)) {
				Set<String> collect = customerList.stream().map(RoomSaleChartCustomerRespVo::getCustomerId).collect(Collectors.toSet());
				customerIdSet.addAll(collect);
			}
		}
		
		//护理房间
		Map<String, List<RoomSaleChart2RespVo>> map = huliList.stream().collect(Collectors.groupingBy(RoomSaleChart2RespVo::getRoom));
		Set<Entry<String, List<RoomSaleChart2RespVo>>> entrySet = map.entrySet();
		for (Entry<String, List<RoomSaleChart2RespVo>> entry : map.entrySet()) {
			List<RoomSaleChart2RespVo> valueList = entry.getValue();
			RoomSaleChart2RespVo orElse = valueList.stream().filter(e->"入住中".equals(StringUtils.isBlank(e.getStatus())?"":e.getStatus())).findAny().orElse(null);
			if(null!=orElse) {
				chechInRoomNumTotal = chechInRoomNumTotal+1;	
			}
			
			RoomSaleChart2RespVo orElse2 = valueList.stream().filter(e->!"不可租".equals(StringUtils.isBlank(e.getStatus())?"":e.getStatus())).findAny().orElse(null);
			if(null==orElse2) {
				notRentRoomNumTotal = notRentRoomNumTotal+1;	
			}
		}
		roomNumTotal = roomNumTotal + entrySet.size();
		peopleNumTotal = customerIdSet.size();
		
		
		result.setRoomNumTotal(roomNumTotal);
		result.setChechInRoomNumTotal(chechInRoomNumTotal);
		result.setNotRentRoomNumTotal(notRentRoomNumTotal);
		result.setBedNumTotal(bedNumTotal);
		result.setChechInBedNumTotal(chechInBedNumTotal);
		result.setNotRentBedNumTotal(notRentBedNumTotal);
		result.setPeopleNumTotal(peopleNumTotal);
		result.setOccupyBedNumTotal(occupyBedNumTotal);
		
		return result;
	}


	/**护理-获取床位
	 * @return
	 */
	private String getRoom(String roomName,String room) {
		if(StringUtils.isNotBlank(room)) {
			return room;
		}
		if(StringUtils.isBlank(roomName)) {
			return "";
		}
		if(roomName.contains("-")) {
			String[] split = roomName.split("-");
			return split[0];
		}
		if(roomName.substring(roomName.length() - 1).matches(".*[a-zA-Z]$")) {
			return roomName.substring(0, roomName.length()-1);
		}
		/*201-C
		1001-2
		301A
		507B
		8A38B
		8819A
		1503A
		606B
		1004*/
		return roomName;
	}


	@Override
	public RoomSalesChartRespVo getSaleCount(List<String> buildings, List<String> floors, String roomType, List<String> deptIds) {
		RoomSalesChartRespVo result = new RoomSalesChartRespVo();
		if(CollectionUtils.isEmpty(deptIds)) {
			deptIds = Arrays.asList(UserAndDeptUtils.getCurrentDeptId());
		}
		String url = ROOM_INFO+"?currentUserId="+UserAndDeptUtils.getCurrentUserId()+"&currentDeptId="+UserAndDeptUtils.getCurrentDeptId();
		String key = ROOM_INFO;
		if(!CollectionUtils.isEmpty(deptIds)) {
			url = url+"&deptIds="+String.join(",", deptIds);
			key = key+"&deptIds="+String.join(",", deptIds);
		}
		if(!CollectionUtils.isEmpty(buildings)) {
			url = url+"&buildings="+String.join(",", buildings);
			key = key+"&buildings="+String.join(",", buildings);
		}
		if(!CollectionUtils.isEmpty(floors)) {
			url = url+"&floors="+String.join(",", floors);
			key = key+"&floors="+String.join(",", floors);
		}
		if(StringUtils.isNotBlank(roomType)) {
			url = url+"&roomType="+roomType;
			key = key+"&roomType="+roomType;
		}
		//String resp = requestManageService.getMethod(url, String.class);
		String resp = getResp(url,key);

		if(StringUtils.isBlank(resp)) {
			return result;
		}
		List<RoomSaleChart2RespVo> roomBuildingNumberList = JSON.parseObject(resp).getList("data",RoomSaleChart2RespVo.class);
		if(CollectionUtils.isEmpty(roomBuildingNumberList)) {
			return result;
		}
		
		//总房间数
		Integer roomNumTotal = 0;
		//入住房间数
		Integer chechInRoomNumTotal = 0;
		//不可租房间数
		Integer notRentRoomNumTotal = 0;
		
		//总床位数
		Integer bedNumTotal = 0;
		//入住床位数
		Integer chechInBedNumTotal = 0;
		//不可租床位数
		Integer notRentBedNumTotal = 0;
		
		//入住人数
		Integer peopleNumTotal = 0;
		//占用床位数
		Integer occupyBedNumTotal = 0;
		
		//人数
		Set<String> customerIdSet = new HashSet<>();
		//护理
		List<RoomSaleChart2RespVo> huliList = new ArrayList<RoomSaleChart2RespVo>();
		
		for (RoomSaleChart2RespVo roomSaleChart2RespVo : roomBuildingNumberList) {
			String roomType2 = roomSaleChart2RespVo.getRoomType();
			String roomStatus = StringUtils.isBlank(roomSaleChart2RespVo.getStatus())?"":roomSaleChart2RespVo.getStatus();
			String number = StringUtils.isBlank(roomSaleChart2RespVo.getNumber())?"":roomSaleChart2RespVo.getNumber();
			if("自理".equals(roomType2) || "短住".equals(roomType2)) {
				if("入住中".equals(roomStatus)) {
					chechInRoomNumTotal=chechInRoomNumTotal+1;
					if("单人间".equals(number)) {
						chechInBedNumTotal = chechInBedNumTotal+1;
					}else {
						chechInBedNumTotal = chechInBedNumTotal+2;
					}
				}
				if("不可租".equals(roomStatus)) {
					notRentRoomNumTotal=notRentRoomNumTotal+1;
					if("单人间".equals(number)) {
						notRentBedNumTotal = notRentBedNumTotal+1;
					}else {
						notRentBedNumTotal = notRentBedNumTotal+2;
					}
				}
				if("单人间".equals(number)) {
					bedNumTotal = bedNumTotal+1;
				}else {
					bedNumTotal = bedNumTotal+2;
				}
				roomNumTotal = roomNumTotal+1;
			}
			
			if("护理".equals(roomType2)) {
				String room = roomSaleChart2RespVo.getRoom();
				String checkInSituation = StringUtils.isBlank(roomSaleChart2RespVo.getCheckInSituation())?"":roomSaleChart2RespVo.getCheckInSituation();
				if(StringUtils.isBlank(room)) {
					roomSaleChart2RespVo.setRoom(this.getRoom(roomSaleChart2RespVo.getRoomName(),roomSaleChart2RespVo.getRoom()));
				}
				if("入住中".equals(roomStatus)) {
					chechInBedNumTotal=chechInBedNumTotal+1;
				}
				if("不可租".equals(roomStatus)) {
					notRentBedNumTotal=notRentBedNumTotal+1;
				}
				if(checkInSituation.contains("占用")) {
					occupyBedNumTotal = occupyBedNumTotal+1;
				}
				bedNumTotal = bedNumTotal+1;
				huliList.add(roomSaleChart2RespVo);
			}
			
			//人员
			List<RoomSaleChartCustomerRespVo> customerList = roomSaleChart2RespVo.getCustomerList();
			if(!CollectionUtils.isEmpty(customerList)) {
				Set<String> collect = customerList.stream().map(RoomSaleChartCustomerRespVo::getCustomerId).collect(Collectors.toSet());
				customerIdSet.addAll(collect);
			}
		}
		
		//护理房间
		Map<String, List<RoomSaleChart2RespVo>> map = huliList.stream().collect(Collectors.groupingBy(RoomSaleChart2RespVo::getRoom));
		Set<Entry<String, List<RoomSaleChart2RespVo>>> entrySet = map.entrySet();
		for (Entry<String, List<RoomSaleChart2RespVo>> entry : map.entrySet()) {
			List<RoomSaleChart2RespVo> valueList = entry.getValue();
			RoomSaleChart2RespVo orElse = valueList.stream().filter(e->"入住中".equals(StringUtils.isBlank(e.getStatus())?"":e.getStatus())).findAny().orElse(null);
			if(null!=orElse) {
				chechInRoomNumTotal = chechInRoomNumTotal+1;	
			}
			
			RoomSaleChart2RespVo orElse2 = valueList.stream().filter(e->!"不可租".equals(StringUtils.isBlank(e.getStatus())?"":e.getStatus())).findAny().orElse(null);
			if(null==orElse2) {
				notRentRoomNumTotal = notRentRoomNumTotal+1;	
			}
		}
		roomNumTotal = roomNumTotal + entrySet.size();
		peopleNumTotal = customerIdSet.size();
		
		
		result.setRoomNumTotal(roomNumTotal);
		result.setChechInRoomNumTotal(chechInRoomNumTotal);
		result.setNotRentRoomNumTotal(notRentRoomNumTotal);
		result.setBedNumTotal(bedNumTotal);
		result.setChechInBedNumTotal(chechInBedNumTotal);
		result.setNotRentBedNumTotal(notRentBedNumTotal);
		result.setPeopleNumTotal(peopleNumTotal);
		result.setOccupyBedNumTotal(occupyBedNumTotal);
		return result;		
	}


	@Override
	public IPage<RoomSaleChart2RespVo> getSaleCountData(List<String> buildings, List<String> floors, String roomType,
			String status, List<String> deptIds, String conditions, Integer pageNum, Integer pageSize) {
		IPage page = new Page();
		page.setCurrent(pageNum);
		page.setSize(pageSize);
		page.setTotal(0);
		if(CollectionUtils.isEmpty(deptIds)) {
			deptIds = Arrays.asList(UserAndDeptUtils.getCurrentDeptId());
		}
		String url = ROOM_INFO+"?currentUserId="+UserAndDeptUtils.getCurrentUserId()+"&currentDeptId="+UserAndDeptUtils.getCurrentDeptId();
		String key = ROOM_INFO;
		if(!CollectionUtils.isEmpty(deptIds)) {
			url = url+"&deptIds="+String.join(",", deptIds);
			key = key+"&deptIds="+String.join(",", deptIds);
		}
		if(!CollectionUtils.isEmpty(buildings)) {
			url = url+"&buildings="+String.join(",", buildings);
			key = key+"&buildings="+String.join(",", buildings);
		}
		if(!CollectionUtils.isEmpty(floors)) {
			url = url+"&floors="+String.join(",", floors);
			key = key+"&floors="+String.join(",", floors);
		}
		if(StringUtils.isNotBlank(status)) {
			url = url+"&status="+status;
			key = key+"&status="+status;
		}
		if(StringUtils.isNotBlank(roomType)) {
			url = url+"&roomType="+roomType;
			key = key+"&roomType="+roomType;
		}
		//String resp = requestManageService.getMethod(url, String.class);
		String resp = getResp(url,key);

		if(StringUtils.isBlank(resp)) {
			return page;
		}
		List<RoomSaleChart2RespVo> roomBuildingNumberList = JSON.parseObject(resp).getList("data",RoomSaleChart2RespVo.class);
		if(CollectionUtils.isEmpty(roomBuildingNumberList)) {
			return page;
		}
		
		// 填充数据
		List<SysDictData> projectData = dictTypeService.selectDictDataByType("project_manage");
		for (RoomSaleChart2RespVo roomSaleChart2RespVo : roomBuildingNumberList) {
			//部门
			SysDictData sysDictData = projectData.stream()
					.filter(e -> roomSaleChart2RespVo.getDeptId().equals(e.getDictValue())).findAny().orElse(null);
			roomSaleChart2RespVo.setDeptName(null == sysDictData ? null : sysDictData.getDictLabel());
			//入住状态
			String roomStatus = StringUtils.isBlank(roomSaleChart2RespVo.getStatus())?"":roomSaleChart2RespVo.getStatus();
			if("入住中".equals(roomStatus)) {
				roomSaleChart2RespVo.setCheckInStatus("已入住");
			}else {
				roomSaleChart2RespVo.setCheckInStatus("未入住");
			}
			//客房类型
			roomSaleChart2RespVo.setRoomType(roomType);
		}
		
		//解析查询条件
		roomBuildingNumberList = this.parseParem(conditions,roomBuildingNumberList);
		
		roomBuildingNumberList.sort((RoomSaleChart2RespVo r1,RoomSaleChart2RespVo r2)->{
			int compareTo = Integer.valueOf(r1.getBuilding()).compareTo(Integer.valueOf(r2.getBuilding()));
			if(0==compareTo) {
				int compareTo2 = Integer.valueOf(r1.getFloor()).compareTo(Integer.valueOf(r2.getFloor()));
				if(0==compareTo2) {
					return r1.getRoomName().compareTo(r2.getRoomName());
				}
				return compareTo2;
			}
			return compareTo;
		});
		
		//分页
		List<RoomSaleChart2RespVo> collect = roomBuildingNumberList.stream().skip((pageNum - 1) * pageSize).limit(pageSize)
		.collect(Collectors.toList());
		page.setRecords(collect);
		page.setCurrent(pageNum);
		page.setSize(pageSize);
		page.setTotal(roomBuildingNumberList.size());
		return page;
	}


	private List<RoomSaleChart2RespVo> parseParem(String conditions,
			List<RoomSaleChart2RespVo> roomBuildingNumberList) {
		List<RoomSaleChart2RespVo> result = roomBuildingNumberList;
		if(StringUtils.isBlank(conditions)) {
			return result;
		}
		List<ConditionReqVO> conditionList = JSON.parseArray(conditions, ConditionReqVO.class);
		for (ConditionReqVO conditionReqVO : conditionList) {
			List<RoomSaleChart2RespVo> tempList = new ArrayList<RoomSaleChart2RespVo>();
			String field = conditionReqVO.getField();
			String operator = conditionReqVO.getOperator();
			List<Object> value = conditionReqVO.getValue();
			
			for (RoomSaleChart2RespVo roomSaleChart2RespVo : result) {
				if("roomType".equals(field)) {
					String roomType = roomSaleChart2RespVo.getRoomType();
					if(StringUtils.isBlank(roomType)) {
						continue;
					}
					if("EQUALS".equals(operator)) {
						if(((String)value.get(0)).equals(roomType)) {
							tempList.add(roomSaleChart2RespVo);
						}
					}
					if("CONTAIN".equals(operator)) {
						if(roomType.contains((String)value.get(0))) {
							tempList.add(roomSaleChart2RespVo);
						}
					}
				}
				if("deptId".equals(field)) {
					String deptId = roomSaleChart2RespVo.getDeptId();
					if(StringUtils.isBlank(deptId)) {
						continue;
					}
					if(((String)value.get(0)).equals(deptId)) {
						tempList.add(roomSaleChart2RespVo);
					}
				}
				if("deptName".equals(field)) {
					String deptName = roomSaleChart2RespVo.getDeptName();
					if(StringUtils.isBlank(deptName)) {
						continue;
					}
					if(((String)value.get(0)).equals(deptName)) {
						tempList.add(roomSaleChart2RespVo);
					}
				}
				if("vipTypes".equals(field)) {
					String vipTypes = roomSaleChart2RespVo.getVipTypes();
					if(StringUtils.isBlank(vipTypes)) {
						continue;
					}
					if("EQUALS".equals(operator)) {
						if(((String)value.get(0)).equals(vipTypes)) {
							tempList.add(roomSaleChart2RespVo);
						}
					}
					if("CONTAIN".equals(operator)) {
						if(vipTypes.contains((String)value.get(0))) {
							tempList.add(roomSaleChart2RespVo);
						}
					}
				}
				if("checkInStatus".equals(field)) {
					String checkInStatus = roomSaleChart2RespVo.getCheckInStatus();
					if(StringUtils.isBlank(checkInStatus)) {
						continue;
					}
					if("EQUALS".equals(operator)) {
						if(((String)value.get(0)).equals(checkInStatus)) {
							tempList.add(roomSaleChart2RespVo);
						}
					}
					if("CONTAIN".equals(operator)) {
						if(checkInStatus.contains((String)value.get(0))) {
							tempList.add(roomSaleChart2RespVo);
						}
					}
				}
				if("roomName".equals(field)) {
					String roomName = roomSaleChart2RespVo.getRoomName();
					if(StringUtils.isBlank(roomName)) {
						continue;
					}
					if("EQUALS".equals(operator)) {
						if(((String)value.get(0)).equals(roomName)) {
							tempList.add(roomSaleChart2RespVo);
						}
					}
					if("CONTAIN".equals(operator)) {
						if(roomName.contains((String)value.get(0))) {
							tempList.add(roomSaleChart2RespVo);
						}
					}
				}
				if("number".equals(field)) {
					String number = roomSaleChart2RespVo.getNumber();
					if(StringUtils.isBlank(number)) {
						continue;
					}
					if("EQUALS".equals(operator)) {
						if(((String)value.get(0)).equals(number)) {
							tempList.add(roomSaleChart2RespVo);
						}
					}
					if("CONTAIN".equals(operator)) {
						if(number.contains((String)value.get(0))) {
							tempList.add(roomSaleChart2RespVo);
						}
					}
				}
				if("status".equals(field)) {
					String status = roomSaleChart2RespVo.getStatus();
					if(StringUtils.isBlank(status)) {
						continue;
					}
					if("EQUALS".equals(operator)) {
						if(((String)value.get(0)).equals(status)) {
							tempList.add(roomSaleChart2RespVo);
						}
					}
					if("CONTAIN".equals(operator)) {
						if(status.contains((String)value.get(0))) {
							tempList.add(roomSaleChart2RespVo);
						}
					}
				}
				if("face".equals(field)) {
					String face = roomSaleChart2RespVo.getFace();
					if(StringUtils.isBlank(face)) {
						continue;
					}
					if("EQUALS".equals(operator)) {
						if(((String)value.get(0)).equals(face)) {
							tempList.add(roomSaleChart2RespVo);
						}
					}
					if("CONTAIN".equals(operator)) {
						if(face.contains((String)value.get(0))) {
							tempList.add(roomSaleChart2RespVo);
						}
					}
				}
				if("area".equals(field)) {
					BigDecimal area = roomSaleChart2RespVo.getArea();
					if(null==area) {
						continue;
					}
					boolean bo=true;
					if(null!=value.get(0)) {
						if(new BigDecimal(value.get(0)+"").compareTo(area)>0) {
							bo=false;
						}
					}
					if(null!=value.get(1)) {
						if(new BigDecimal(value.get(1)+"").compareTo(area)<0) {
							bo=false;
						}
					}
					if(bo) {
						tempList.add(roomSaleChart2RespVo);
					}
				}
				if("salePrice".equals(field)) {
					BigDecimal salePrice = roomSaleChart2RespVo.getSalePrice();
					if(null==salePrice) {
						continue;
					}
					boolean bo=true;
					if(null!=value.get(0)) {
						if(new BigDecimal(value.get(0)+"").compareTo(salePrice)>0) {
							bo=false;
						}
					}
					if(null!=value.get(1)) {
						if(new BigDecimal(value.get(1)+"").compareTo(salePrice)<0) {
							bo=false;
						}
					}
					if(bo) {
						tempList.add(roomSaleChart2RespVo);
					}
				}
				
			}
			result = tempList;
		}
		
		return result;
	}


	@Override
	public List<RoomSaleChartExcelDTO> getSaleCountDataExport(List<String> buildings, List<String> floors,
			String roomType, String status, List<String> deptIds, String conditions) {
		List<RoomSaleChartExcelDTO> result = new ArrayList<RoomSaleChartExcelDTO>();
		if(CollectionUtils.isEmpty(deptIds)) {
			deptIds = Arrays.asList(UserAndDeptUtils.getCurrentDeptId());
		}
		String url = ROOM_INFO+"?currentUserId="+UserAndDeptUtils.getCurrentUserId()+"&currentDeptId="+UserAndDeptUtils.getCurrentDeptId();
		String key = ROOM_INFO;
		if(!CollectionUtils.isEmpty(deptIds)) {
			url = url+"&deptIds="+String.join(",", deptIds);
			key = key+"&deptIds="+String.join(",", deptIds);
		}
		if(!CollectionUtils.isEmpty(buildings)) {
			url = url+"&buildings="+String.join(",", buildings);
			key = key+"&buildings="+String.join(",", buildings);
		}
		if(!CollectionUtils.isEmpty(floors)) {
			url = url+"&floors="+String.join(",", floors);
			key = key+"&floors="+String.join(",", floors);
		}
		if(StringUtils.isNotBlank(status)) {
			url = url+"&status="+status;
			key = key+"&status="+status;
		}
		if(StringUtils.isNotBlank(roomType)) {
			url = url+"&roomType="+roomType;
			key = key+"&roomType="+roomType;
		}
		//String resp = requestManageService.getMethod(url, String.class);
		String resp = getResp(url,key);

		if(StringUtils.isBlank(resp)) {
			return result;
		}
		List<RoomSaleChart2RespVo> roomBuildingNumberList = JSON.parseObject(resp).getList("data",RoomSaleChart2RespVo.class);
		if(CollectionUtils.isEmpty(roomBuildingNumberList)) {
			return result;
		}
		
		// 填充数据
		List<SysDictData> projectData = dictTypeService.selectDictDataByType("project_manage");
		for (RoomSaleChart2RespVo roomSaleChart2RespVo : roomBuildingNumberList) {
			//部门
			SysDictData sysDictData = projectData.stream()
					.filter(e -> roomSaleChart2RespVo.getDeptId().equals(e.getDictValue())).findAny().orElse(null);
			roomSaleChart2RespVo.setDeptName(null == sysDictData ? null : sysDictData.getDictLabel());
			//入住状态
			String roomStatus = StringUtils.isBlank(roomSaleChart2RespVo.getStatus())?"":roomSaleChart2RespVo.getStatus();
			if("入住中".equals(roomStatus)) {
				roomSaleChart2RespVo.setCheckInStatus("已入住");
			}else {
				roomSaleChart2RespVo.setCheckInStatus("未入住");
			}
			//客房类型
			roomSaleChart2RespVo.setRoomType(roomType);
		}
		
		//解析查询条件
		roomBuildingNumberList = this.parseParem(null,roomBuildingNumberList);
		
		roomBuildingNumberList.sort((RoomSaleChart2RespVo r1,RoomSaleChart2RespVo r2)->{
			int compareTo = Integer.valueOf(r1.getBuilding()).compareTo(Integer.valueOf(r2.getBuilding()));
			if(0==compareTo) {
				int compareTo2 = Integer.valueOf(r1.getFloor()).compareTo(Integer.valueOf(r2.getFloor()));
				if(0==compareTo2) {
					return r1.getRoomName().compareTo(r2.getRoomName());
				}
				return compareTo2;
			}
			return compareTo;
		});
		
		//分页
		return BeanUtil.toBeans(roomBuildingNumberList, RoomSaleChartExcelDTO.class);
	}


	private String getResp(String url,String key) {
		String resp = (String)redisClient.get(key);
		if(StringUtils.isBlank(resp)) {
			resp = requestManageService.getMethod(url, String.class);
			redisClient.set(key, resp, 2*60*60);
		}
		return resp;
	}

}
